var arr = new Array(5).fill(0);
var nums = [1,2,3,4,5];

console.log(randomAccess(nums));
printArray(arr);
printArray(nums);
nums=extend(nums,10);
printArray(nums);

function randomAccess(nums) {
    const random_index = Math.floor(Math.random() * nums.length);
    const random_num = nums[random_index];
    return random_num;
}
function insert(nums,num,index){
    for (let i =nums.length-1; i >index; i--){
        nums[i] = nums[i-1];
    }
    nums[index] = num;
}
function remove(nums,index){
    for(let i=index; i<nums.length-1; i++){
        nums[i]=nums[i+1];
    }

}

function find(nums, target) {
    for (let i = 0; i < nums.length; i++) {
        if (nums[i] === target) return i;
    }
    return -1;
}

function extend(nums,enlarge){
    const res = new Array(nums.length+enlarge).fill(0);
    for (let i=0;i<nums.length;i++){
        res[i] = nums[i];
    }
    // nums=res;
    return res;
}

function printArray(nums){
    let formatStr='';
    for (let i=0;i<nums.length;i++) {
        formatStr+=nums[i].toString()+' ';
    }
    console.log(formatStr);
}